package com.rmb.dataanalysis.pool;

import com.rmb.common.model.state.TaskStatus;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.concurrent.RecursiveTask;

/**
 * @version 1.0
 * @Author ZhaoMuYang
 * @Date 2021/1/15 0:49
 */
@Slf4j
public class DataAnalysisDimQueryTask  extends RecursiveTask<List<String>>{

    public static final int THRESHOLD=2;
    private final List<Map<String,Object>> dataSource;
    private final int start;
    private final int end;

    public DataAnalysisDimQueryTask(List<Map<String, Object>> allDataSource){
        this.dataSource=allDataSource;
        this.start= TaskStatus.EXECUTOR_COTACT_STATUS.getStatus();
        this.end=allDataSource.size();
    }

    @Override
    protected List<String> compute() {
        List<Map<String, List<Map<String, List>>>> arrayList = new ArrayList<>();

        Map<Set<String>, List<Map<String, List>>> dataSourceMap = new HashMap<>(256);
        List<Map<String, List>> dataBase = new ArrayList<>();
        Map<String, List> dataBaseMap = new HashMap<>(256);
        List<String> tables = new ArrayList<>();

        //如果数据源足够少就只单独执行
        boolean canCompute=(end - start) <= THRESHOLD;
        if(canCompute){
            //查询所有数据源以及所有表
            //获取所有描述与数据源ID
            this.dataSource.stream().map(Map::keySet).forEach(key -> {
                dataSourceMap.put(key, dataSourceMap.get(key));
                System.out.println(dataBaseMap);
                Set<Set<String>> setSet = dataSourceMap.keySet();

                System.out.println(dataBaseMap);
            });
        }else{
            //如果任务大于阈值，就分成数据源个数相同子任务执行
            for (int i=start;i<end;i++){
            }
        }
        return null;
    }

}
